<%--
  Created by IntelliJ IDEA.
  User: Lemon
  Date: 2020/6/11
  Time: 14:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>时间统计客户</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!-- 引入 ECharts 文件 -->
    <script src="${pageContext.request.contextPath}/static/js/echarts.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css"  media="all">
</head>
<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md12">
            <form class="layui-form" action="" style="margin-top:30px;">
                <div class="layui-form-item" style="text-align:center;">
                    <div class="layui-inline">
                        <label class="layui-form-label">统计对象</label>
                        <div class="layui-input-inline" style="width:100px;">
                            <select name="selectType" lay-filter="report-object">
                                <option value="1010" selected>新增客户</option>
                                <option value="1020" >新增跟进记录</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">统计粒度</label>
                        <div class="layui-input-inline" style="width:100px;">
                            <select name="action" lay-filter="select-action">
                                <option value="year" >年</option>
                                <option value="month" selected>月</option>
                                <option value="day">日</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">时间</label>
                        <div class="layui-input-inline" style="width:100px;">
                            <select name="year" id="date-year" class="layui-input">

                            </select>
                        </div>
                        <div id="date-month-div" class="layui-input-inline layui-hide" style="width:100px;">
                            <select name="month" id="date-month">
                                <option value="01" selected>1月</option>
                                <option value="02">2月</option>
                                <option value="03">3月</option>
                                <option value="04">4月</option>
                                <option value="05">5月</option>
                                <option value="06">6月</option>
                                <option value="07">7月</option>
                                <option value="08">8月</option>
                                <option value="09">9月</option>
                                <option value="10">10月</option>
                                <option value="11">11月</option>
                                <option value="12">12月</option>
                            </select>
                        </div>
                        <button id="customerButton" class="layui-btn layui-btn-primary" type="button">确定</button>
                    </div>
                </div>
            </form>
            <div id="timeStatisticsCustomer" style="width:100%;height:500px">
            </div>
        </div>
    </div>
</div>
</body>
<script src="${pageContext.request.contextPath}/static/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use(['element','jquery','layer','form','laydate','layedit'], function() {
        var $ = layui.jquery
            ,element = layui.element;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;

        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('timeStatisticsCustomer'));

        var option = {
            title: {
                text: '客户新增趋势',
            },
            tooltip:{  //鼠标经过显示提示框
                show : true,
                trigger: "axis"
            },
            legend:{  //不同的线的类型
                data: ["客户新增量"]
            },
            toolbox:{  //工具栏
                show: true,
                feature:{
                    dataView: {readOnly: false},
                    magicType: {type: ['line', 'bar']},  //图形切换
                    restore: {},
                    saveAsImage: {}
                }
            },
            dataZoom: [  //滚动条
                {
                    type: 'slider',
                    show: true,
                    start: 0,
                    end: 100
                }
            ],
            xAxis: {
                name: "时间",
                type: 'category',
                data: ['2020-01', '2020-02', '2020-03', '2020-04', '2020-05', '2020-06', '2020-07','2020-08','2020-09','2020-10','2020-11','2020-12']
            },
            yAxis: {
                name: "新增客户量",
                type: 'value',
                max : 12,
                min : 0,
                splitNumber : 6,
            },
            series: [
                {
                    name: '客户新增量',
                    type: 'line',
                    data: [1, 3, 7, 4, 6, 12, 6 , 7, 1, 3, 4,1]
                }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);

        function init(){
            var year = new Date().getFullYear();

            var str = '';
            for(var i=year-10;i<=year+10;i++){
                if(i == year){
                    str += '<option value="' + i + '" selected>' + i + '</option>';
                }else{
                    str += '<option value="' + i + '">' + i + '</option>';
                }
            }
            $('#date-year').html(str);
            form.render("select");

        }

        init();

        //监听查询方式选择
        form.on('select(select-action)',function(data){
            if(data.value == 'day'){
                $('#date-month-div').removeClass('layui-hide');
            }else{
                $('#date-month-div').addClass('layui-hide');
            }
        });

    });
</script>

</html>